package com.study.hot.jetpack.room.many2many

import androidx.room.*

/**
 * <pre>
 *     author : slx
 *     time   : 2021/02/25
 *     desc   : 老师与学生的多对多
 * </pre>
 */
@Entity
data class Stu(
        @PrimaryKey var sId: Int,
        var sName: String
)

@Entity
data class Teacher(
        @PrimaryKey var tId: Int,
        var tName: String,
)


// 老师与学生关联表(交叉引用表)
@Entity(primaryKeys = ["sId", "tId"])
data class StuTeacherCrossRef(
        val sId: Int,
        val tId: Int
)

// 使用Junction关联 多对多关系
data class StuWithTeachers(
        @Embedded val stu: Stu,
        @Relation(
                parentColumn = "sId",
                entityColumn = "tId",
                entity = Teacher::class,
                associateBy = Junction(StuTeacherCrossRef::class)
        )
        val teachers: List<Teacher>
)